#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
bool Bits[32][2];
char buf[10];

int main() {
#ifdef hai
    freopen("in.txt", "r", stdin);
#endif
    int n,m,t;
    int op;
    while (~scanf("%d %d", &n, &m)) {
        for (int i=0; i<32; ++i) {
            Bits[i][0] = 0;
            Bits[i][1] = 1;
        }
        for (int i=0; i<n; ++i) {
            scanf("%s %d", buf, &t);
            if (strcmp(buf, "AND") == 0) op = 1;
            if (strcmp(buf, "OR") == 0) op = 2;
            if (strcmp(buf, "XOR") == 0) op = 3;
            int p = 0;
            int ti = 32;
            while (ti--) {
                int b = t&1;
                switch(op) {
                    case 1:
                        Bits[p][0] &= b;
                        Bits[p][1] &= b;
                        break;
                    case 2:
                        Bits[p][0] |= b;
                        Bits[p][1] |= b;
                        break;
                    default:
                        Bits[p][0] ^= b;
                        Bits[p][1] ^= b;
                }
                ++p;
                t = (t>>1);
            }
        }
//        for (int i=0; i<32; ++i) printf("%d", Bits[i][0]);
//        printf("\n");
//        for (int i=0; i<32; ++i) printf("%d", Bits[i][1]);
//        printf("\n");
        int c = 0;
        int res = 0;
        for (int i=30; i>=0; --i) {
            if (Bits[i][0] == 1) {
                res += (1<<i);
                continue;
            }
            if (Bits[i][1] == 1) {
                if (c + (1<<i) <= m) {
                    c += (1<<i);
                    res += (1<<i);
                }
            }
        }
        printf("%d\n", res);
    }
    return 0;
}
